import json
def loadjson(filename):
    dic = json.load(open(filename))
    ret = {}
    for i, j in dic.items():
        ret[int(i)] = j
    return ret
def savejson(obj, filename):
    json.dump(obj, open(filename, 'w'), separators=(',', ":"), ensure_ascii=False)
names = loadjson("data/names.json")
max_life = loadjson("data/max_life.json")
attack = loadjson("data/attack.json")
defense = loadjson("data/defense.json")
possibility = loadjson("data/possibility.json")
skills = {
    21: [2101, 2102],
    22: [2201, 2202],
    23: [2301, 2302],
    24: [2401],
    25: [2501],
    26: [2601],
    27: [2701],
    28: [2801],
    29: [2901],
    30: [3001],
    31: [3101],
    32: [3201, 3202]
}
skill_names = {
    2101: "杂交水稻",
    2102: "树精",
    2201: "变鸭子",
    2202: "抓鸭子",
    2301: "美丽而苍凉的手势",
    2302: "美丽中国话",
    2401: "",
    2501: "飞机坠毁航母爆炸",
    2601: "球体",
    2701: "",
    2801: "",
    2901: "",
    3001: "短跑",
    3101: "写公众号",
    3201: "太阳的暴怒",
    3202: "正道的光",
    3301: "",
    3401: "有难同当",
    3501: "",
    3601: "偷懒",
    3701: "",
    3801: "",
    3901: "有难同当",
    4001: "",
    4101: "布置作业"
}
class Charactor:
    def __init__(self, attack, defense, max_life, skills):
        self.attack = attack
        self.defense = defense
        self.max_life = max_life
        self.life = max_life
        self.buffs = []
        self.gameover = False
    
    def be_attack(self, att):
        cdef = self.defense
        self.life -= max(att - cdef, 1)
        if self.life <= 0:
            self.gameover = True